import { dataManage, RouterType, router } from './index';
const introduce = [
  {
    name: 'introduce',
    chname: '介绍',
    path: `/`,
    children: []
  }
];
export const menuData = (introduce as RouterType[]).concat([
  {
    chname: '后台管理',
    name: 'manage',
    path: `/manage`,
    children: dataManage
  }
]);
export const menuRouter = (introduce as RouterType[]).concat(menuData);

type MenuName = { pName: string; pChName: string };
/**获取父名*/
export const getParentRouterName = (nodes: typeof menuRouter, menuName: MenuName = { pName: '', pChName: '' }): MenuName => {
  let mname: MenuName = { pName: '', pChName: '' };
  nodes.forEach((node) => {
    if (node.name === router.currentRoute.value.name) {
      mname = menuName;
    }
    if (node.children && mname.pName === '') {
      mname = getParentRouterName(node.children as typeof menuRouter, { pName: node.name as string, pChName: node.chname! });
    }
  });
  return mname;
};
